/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * FrequencyPanel.java
 *
 * Created on 2010-9-29, 15:35:15
 */
package dataanalysis.gui.statisticPanel;

import java.awt.BorderLayout;
import java.util.Vector;
import weka.core.Instances;
import weka.gui.AttributeVisualizationPanel;

/**
 *
 * @author Administrator
 */
public class FrequencyPanel extends javax.swing.JPanel {

    /** The visualization of the attribute values */
    private final AttributeVisualizationPanel m_attVisualizePanel = new AttributeVisualizationPanel();

    /** Creates new form FrequencyPanel */
    public FrequencyPanel() {
        initComponents();
        m_visualPanel.setLayout(new BorderLayout());
        m_visualPanel.add(m_attVisualizePanel);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        m_attList = new javax.swing.JList();
        m_visualPanel = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();

        m_attList.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                m_attListValueChanged(evt);
            }
        });
        jScrollPane1.setViewportView(m_attList);

        m_visualPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        javax.swing.GroupLayout m_visualPanelLayout = new javax.swing.GroupLayout(m_visualPanel);
        m_visualPanel.setLayout(m_visualPanelLayout);
        m_visualPanelLayout.setHorizontalGroup(
            m_visualPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 353, Short.MAX_VALUE)
        );
        m_visualPanelLayout.setVerticalGroup(
            m_visualPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 239, Short.MAX_VALUE)
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 353, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 147, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 218, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(m_visualPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 412, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addComponent(m_visualPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGap(18, 18, 18)
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void m_attListValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_m_attListValueChanged
        int index=m_attList.getSelectedIndex();
        if(index!=-1) {
            m_attVisualizePanel.setAttribute(index);
        }
    }//GEN-LAST:event_m_attListValueChanged

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JList m_attList;
    private javax.swing.JPanel m_visualPanel;
    // End of variables declaration//GEN-END:variables

    public void setInstances(Instances data) {
        m_attVisualizePanel.setInstances(data);
        Vector<String> listVector = new Vector();
        for (int i = 0; i < data.numAttributes(); i++) {
            listVector.add(data.attribute(i).name());
        }
        m_attList.setListData(listVector);
        m_attList.setSelectedIndex(0);
        m_attList.updateUI();
    }
}
